package com.hanbang.taitaigou.ui.widget;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import com.hanbang.taitaigou.utils.other.ObjectUtils;


public class BannerAdView extends RelativeLayout {

	public BannerAdView(Context context, AttributeSet attrs, int defStyle) {
		this(context, attrs);
	}

	public BannerAdView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	public BannerAdView(Context context) {
		this(context, null);
	}

	private void initView(Context context) {
		LayoutParams mainLayoutParams = new LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

		ViewPager viewPager = new ViewPager(context);
		mainLayoutParams.width = LayoutParams.MATCH_PARENT;
		mainLayoutParams.height = LayoutParams.WRAP_CONTENT;
		viewPager.setLayoutParams(mainLayoutParams);
		viewPager.setId(1);
		addView(viewPager);

		LinearLayout layout = new LinearLayout(context);
		LayoutParams rp2 = new LayoutParams(
				ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		rp2.addRule(RelativeLayout.ALIGN_BOTTOM, 1);
		LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		int padding = ObjectUtils.dip2px(context, 5);
		layout.setPadding(padding, padding, padding, padding);
		layout.setOrientation(LinearLayout.VERTICAL);
		lp2.gravity = Gravity.CENTER;
		layout.setLayoutParams(lp2);

		RadioGroup radioGroup = new RadioGroup(context);
		LinearLayout.LayoutParams linLayoutParams = new LinearLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		linLayoutParams.gravity = Gravity.CENTER;
		radioGroup.setOrientation(RadioGroup.HORIZONTAL);
		radioGroup.setGravity(Gravity.CENTER);
		radioGroup.setLayoutParams(linLayoutParams);
		layout.addView(radioGroup, linLayoutParams);

		addView(layout, rp2);

	}
}
